package simple.flow.modules.system.controller;

import simple.flow.common.RestResult;
import simple.flow.modules.system.dto.login.LoginDTO;
import simple.flow.modules.system.dto.login.RegisterDTO;
import simple.flow.modules.system.service.LoginService;
import simple.flow.modules.system.vo.login.LoginVO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * 登录注册相关接口
 *
 * @author lhd
 * @since 2025/4/8 10:37
 */

@Slf4j
@Validated
@Tag(name = "模板框架-登录相关")
@RestController
@RequestMapping("/sys/user")
public class LoginController {

    @Resource
    private LoginService longinService;

    @Operation(summary = "用户登录")
    @PostMapping("/login")
    public RestResult<LoginVO> login(@RequestBody @Valid LoginDTO loginDTO) {
        return RestResult.success(longinService.login(loginDTO));
    }

    @Operation(summary = "退出登录")
    @PostMapping("/logout")
    public RestResult<?> logout() {
        longinService.logout();
        return RestResult.success();
    }

    @Operation(summary = "用户注册")
    @PostMapping("/register")
    public RestResult<?> register(@RequestBody @Valid RegisterDTO registerDTO) {
        longinService.register(registerDTO);
        return RestResult.success();
    }
}
